// pages/row/index.js
const app = getApp()
import http from '../../utils/request.js';
import alert from '../../utils/alert.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone:'',
    is_row_line:'0',
    typeLists:[],
    max_line_fail_num:'1',
    scrollHeight: "500px",
    buttons: [{
      type: 'assertive',
      block: true,
      text: '联系店内',
    }
    ],
    resultIcon: {
      type: 'info',
    },
    row:{},
    rowPopup:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var res = wx.getSystemInfoSync();
    this.setData({
      phone: options.phone,
      scrollHeight: res.windowHeight - 105 + 'px'
    })
    this.getRowList();
    this.getMyRow();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  callPhone: function (e) {
    wx.makePhoneCall({ phoneNumber:this.data.phone });
  },

  getRowList:function(){
    http.post(app.config.service.getRowList, {

    }).then(data => {
      this.setData({
        is_row_line:data.is_row_line,
        typeLists:data.lists,
        max_line_fail_num: data.max_line_fail_num
      })
    }, err => {
      alert.alert(err)
    });
  },
  addType:function(e){
    console.log(e.currentTarget.dataset.data)
    this.setData({
      rowPopup: true,
      rowData: e.currentTarget.dataset.data
    })
  },
  getMyRow:function(){
    http.get(app.config.service.getMyRow).then(data => {
      this.setData({
        row:data
      })
    }, err => {
      alert.alert(err)
    });
  },
  onCloseRowPopup:function(){
    this.setData({
      rowPopup:false
    })
  },
  rowSubmit:function(e){
    http.post(app.config.service.addRow, {
      row_id:this.data.rowData.id,
      person_num: e.detail.value.person_num
    }).then(data => {
      this.getRowList();
      this.getMyRow();
      this.setData({
        rowPopup: false
      })
    }, err => {
      alert.alert(err)
    });
  },
  cancelRow:function(){
    http.post(app.config.service.cancelRow, {
      order_no: this.data.row.order_no,
    }).then(data => {
      this.getRowList();
      this.getMyRow();
    }, err => {
      alert.alert(err)
    });
  }
})